package com.darker.yygh.user.api;

import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.vo.user.LoginVo;
import com.atguigu.yygh.vo.user.UserAuthVo;
import com.darker.yygh.result.Result;
import com.darker.yygh.user.service.UserInfoService;
import com.darker.yygh.utils.AuthContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/user")
@Api("用户登录模块")
public class UserInfoController {
    @Autowired
    UserInfoService userInfoService;
    @ApiOperation("用户手机号登录接口")
    //用户手机号登录接口
    @PostMapping("login")
    public Result login(@RequestBody LoginVo loginVo){
       Map<String,Object> usermap= userInfoService.loginUser(loginVo);
        return Result.ok(usermap);

    }

    //用户认证
    @PostMapping("/auth/userAuth")
    public Result userAuth(@RequestBody  UserAuthVo userAuthVo, HttpServletRequest request){
        Long userId = AuthContextHolder.getUserId(request);
        userInfoService.userAuth(userId,userAuthVo);
        return Result.ok();

    }

    //根据用户Id获取信息
    @GetMapping("auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest request) {
        Long userId = AuthContextHolder.getUserId(request);
        UserInfo userInfo = userInfoService.getById(userId);
        return Result.ok(userInfo);
    }



}
